package authorize

import (
	"MoSkeleton/framework/core/consts"
	"MoSkeleton/framework/core/dto/response"
	"MoSkeleton/services"
	"github.com/gin-gonic/gin"
)

func DoCheckBlackToken() gin.HandlerFunc {
	return func(c *gin.Context) {
		authType, authTypeExists := c.Get(consts.GinContext_AuthType_Key)
		token, tokenExists := c.Get(consts.GinContext_Token_Key)
		if !authTypeExists || !tokenExists {
			c.Next()
			return
		}
		if services.ServiceGroupInst.SystemGroupInst.BlackTokenServiceInst.ExistsBlackToken(token.(string), consts.TokenTypeMap[authType.(string)]) {
			response.FailMsgAsI18n(c, consts.CommonAuthInvalidateCode, consts.TKey_ErrorsTokenExpired)
			return
		}
		c.Next()
	}
}
